<?php
	connect2db();

	function connect2db() {
		$isLocal = $_SERVER['SERVER_NAME'] === "localhost";

		if ($isLocal) {
			$host = "localhost:3306";
			$user = "";
			$pass = "";
			$db_name = "temperature";
		} else {
			$host = "";
			$user = "";
			$pass = "";
			$db_name = "";
		}

		$conn = @mysql_connect($host, $user, $pass);

		if (!$conn) {die("连接数据库失败：" . mysql_error());}

		mysql_select_db($db_name, $conn);

		//字符转换，读库
		mysql_query("set character set utf8");
		//写库
		mysql_query("set names utf8");
	}
?>